package com.example.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author wangjinlong
 * @version 1.0
 * @date 2021/6/29 15:58
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    private static AtomicInteger Insert_num = new AtomicInteger();
    private static AtomicInteger Update_num = new AtomicInteger();

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject, "nickName", String.class, "tom-" + Insert_num.incrementAndGet()); // 起始版本 3.3.0(推荐使用)

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.strictUpdateFill(metaObject, "nickName", String.class, "tom-" + Update_num.incrementAndGet()); // 起始版本 3.3.0(推荐)
    }

}
